package com.dongdongshop.Controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.constant.ResultConstant;
import com.dongdongshop.data.Page;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ConstantEnum;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrandService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("brandController")
public class BrandController {

    @Reference
    private BrandService brandService;

    @RequestMapping("toBrand")
    public String toBrand(){
        return "admin/brand";
    }

    @RequestMapping("findBrandAll")
    @ResponseBody
    public Result findList(){
        List<TbBrand> brandList = brandService.findAll();
        return Result.build(ConstantEnum.SUCCESS).setResult(brandList);
    }

    @RequestMapping("findPage")
    @ResponseBody
    public Result findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "5") Integer pageSize,
                           String name){
        Page<List<TbBrand>> page = brandService.findPage(pageNum,pageSize,name);
        return Result.build(ConstantEnum.SUCCESS).setResult(page);
    }

    @RequestMapping("addInfo")
    @ResponseBody
    public Result addInfo(TbBrand tbBrand){
        boolean b = brandService.addInfo(tbBrand);
        return Result.build(ConstantEnum.SUCCESS);
    }
    @RequestMapping("toUpdate/{id}")
    @ResponseBody
    public Result toUpdate(@PathVariable("id") Integer id){
        TbBrand tbBrand = brandService.toUpdate(id);
        return Result.build(ConstantEnum.SUCCESS);
    }
    @RequestMapping("update")
    @ResponseBody
    public Result update(TbBrand tbBrand){
        boolean b = brandService.update(tbBrand);
        return Result.build(ConstantEnum.SUCCESS);
    }

    @RequestMapping("deleteAll")
    @ResponseBody
    public Result deleteAll(Integer[] arr){
        boolean b = brandService.deleteAll(arr);
        return Result.build(ConstantEnum.SUCCESS);
    }

}
